package in.muton.edushare.pages.batch;

import in.muton.edushare.grading.panels.prevgrades.old.StudentGradeEdit;
import in.muton.edushare.wicket.models.CayenneList;
import in.muton.panels.paginator.EdusharePageNavigator;

import org.apache.wicket.markup.html.CSSPackageResource;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.IModel;

import com.edushare.common.vo.Batches;
import com.edushare.common.vo.Users;

public class BatchGradeEdit extends BatchGradeBase {

	private CayenneList<Users> studentList;
	private int semNum;

	public BatchGradeEdit(IModel<Batches> batchModel, CayenneList<Users> list,
			int sem) {
		super(batchModel);
		add(CSSPackageResource.getHeaderContribution(
				EdusharePageNavigator.class, "EdusharePageNavigator.css"));
		this.studentList = list;
		this.semNum = sem;
		add(new Label("count", studentList.getObject().size() + ""));
		add(new Label("semNum", (semNum + 1) + ""));

		add(new ListView<Integer>("semNavigationLV", StudentGradeEdit
				.makeList(0, batchModel.getObject().getCurrentSemester())) {
			@Override
			protected void populateItem(final ListItem<Integer> arg0) {
				Link<Void> l = new Link<Void>("semLink") {
					@Override
					public void onClick() {
						setResponsePage(new BatchGradeEdit(getBatchModel(),
								studentList, arg0.getModelObject()));
					}

					private static final long serialVersionUID = 2008630008864278757L;
				};
				arg0.add(l);
				l.add(new Label("semNum", (arg0.getModelObject() + 1) + ""));
			}

			private static final long serialVersionUID = -6881218735817290705L;
		});

		add(new ListView<IModel<Users>>("studentGradeEditPanelLV", studentList
				.getObject()) {
			@Override
			protected void populateItem(ListItem<IModel<Users>> arg0) {
				IModel<Users> user = arg0.getModelObject();
				arg0.add(new StudentGradeEdit("studentGradeEdit", user,
						getBatchModel(), semNum, BatchGradeEdit.this));
			}

			private static final long serialVersionUID = -6881218735817290705L;
		});

	}
}
